﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSProject= Microsoft.Office.Interop.MSProject;

namespace DataDesign.MPP.AddIn.Manager
{
    public class ProjectManager
    {
        private static log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private static ProjectManager _projectManager = null;
        public MSProject.Project MsProject { get; set; }
        public MSProject.Application MsAppProject { get; set; }
        #region Contructor
        
        public ProjectManager()
        { }
        public ProjectManager(MSProject.Application appProject, MSProject.Project msProject)
        {
            this.MsAppProject = appProject;
            this.MsProject = msProject;
        }
        
        public static ProjectManager GetInstance()
        {
            if (_projectManager == null)
            {
                _projectManager = new ProjectManager();
            }
            return _projectManager;
        }
        public static ProjectManager GetInstance(MSProject.Application appProject, MSProject.Project msProject)
        {
            _projectManager = new ProjectManager(appProject,msProject);
            return _projectManager;
        }
        #endregion

        #region Public Method
        public MSProject.Resource GetListCustomFeilds()
        {
            try
            {
                string temp = MsProject.GetServerProjectGuid();

               
            }
            catch (Exception ex)
            {

                throw;
            }
            
            return null;
        }
        public List<string> GetListSubProjectName()
        {
            logger.Debug("Begin get list subproject");
            List<string> result = new List<string>();
            try
            {
                
                if (MsProject.Subprojects.Count > 0)
                {
                    for (int i = 1; i <= MsProject.Subprojects.Count; i++)
                    {
                        if (MsProject.Subprojects[i] != null)
                        {
                            result.Add(MsProject.Subprojects[i].SourceProject.Name);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error when get list subproject of project: ",ex);
                throw ex;
            }
            
            return result;
        }
        #endregion
    }
}
